<?php
$data = $_GET['bn'];
$find[] = ',';
$replace[] = ' ';
$data = str_replace($find, $replace, $data);
$id = $_GET['bi'];
$tbl = $_GET['tbl'];
$tblname = "";
if($tbl == "tblbrand"){
$tblname = "Brand:";

}
else if($tbl == "tblmodel"){
$tblname = "Model:";

}
else{
$tblname = "Parts:";

}

?>

<script>
$(document).ready(function (){
$("#edit").click(function (){
	$("#saveEditBox").removeAttr("disabled");
	
});

$("#saveEditBox").click(function (){
	var name = $("#datainput");
	var id = $("#dataid");
	var tbl = $("#tbl");
	$.ajax({
			url:"admin/update.php?bn="+name.val()+"&bi="+id.val()+"&tbl="+tbl.val(),
			success:function(data){
				if(data=="merun"){
					alert("Brand Already Existing");				
				}else{
					alert("Successfully Updated");
					location.reload();
				}
			}
		});
	
});
});	
</script>
<table width="100%">
	<tr>
		<td>
			<?php echo $tblname;?>
		</td>
		<td>
			<input type="text" id="datainput" value="<?php echo $data;?>" />
			<input type="hidden" id="dataid" value="<?php echo $id;?>"/>
			<input type="hidden" id="tbl" value="<?php echo $tbl;?>"/>
		</td>
		
	</tr>
	<tr>
		<td>
			<button id="edit" name="" valign="right" >edit</button>
		</td>
		<td>
			<button id="saveEditBox" name="" disabled>Update</button>
		</td>
	</tr>
</table>
<style>
#datainput{
width:100%;
}
</style>